import React, { Component } from 'react'
import {ListBox} from '../../../components'
import { Modal } from 'antd';
import {fetchData} from '../../../components/AjaxConsumer'
export default class ListProHandOutSnPage extends Component{
    constructor(props) {
        super(props);
        //行操作列表-已弃用
        this.rowOperation = [
            
        ];
        //header 操作列表111
        this.headerOperation = [
            // {
            //     handleName: 'add',
            //     showName: '新增',
            //     iconClass: 'plus'
            // }
        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        // foreverHidden永久隐藏
        this.tableColumn = {
            storageKey: 'handOutSnId',
            data: [
                {
                    showName: 'id',
                    columnName: 'handOutSnId',
                    columnHidden:true,
                    foreverHidden: true
                },
                {
                    showName: '手工出库单号',
                    columnName: 'handOutNo',
                    columnWidth: 130
                },
                {
                    showName: '条码',
                    columnName: 'barcode',
                    columnWidth: 130
                },
                {
                    showName: '型号',
                    columnName: 'model',
                    columnWidth: 120
                },
                {
                    showName: '品名',
                    columnName: 'productName'
                },
                {
                    showName: '定量',
                    columnName: 'density'
                },
                {
                    showName: '规格',
                    columnName: 'spec'
                },
                {
                    showName: '重量',
                    columnName: 'weight'
                },
                {
                    showName: '单位',
                    columnName: 'unit',
                    columnWidth: 80
                }, {
                //     showName: '类型',
                //     columnName: 'type',
                //     showOption: [//页面显示配置
                //         {
                //             optionKey: '0',
                //             optionShow: '正品'
                //         }, {
                //             optionKey: '1',
                //             optionShow: '样品'
                //         }
                //     ]
                // },{
                    showName: '生产机号',
                    columnName: 'machineNumber',
                    showOption: [//页面显示配置
                    ]
                },
                {
                    showName: '等级',
                    columnName: 'grade',
                    showOption: [//页面显示配置
                        {
                            optionKey: '1',
                            optionShow: '一等品'
                        }, {
                            optionKey: '2',
                            optionShow: '二等品'
                        }, {
                            optionKey: '3',
                            optionShow: '处理品'
                        }
                    ]
                },
                {
                    showName: '级别',
                    columnName: 'level'
                },
                {
                    showName: '仓库',
                    columnName: 'waCode',
                    showOption: []
                },
                // {
                //     showName: '库位',
                //     columnName: 'wlCode'
                // },
                {
                    showName: '操作人',
                    columnName: 'createBy'
                },
                {
                    showName: '出库时间',
                    columnName: 'gmtCreate',
                    columnWidth: 140
                }
            ]
        };

        //搜索属性配置，如果字段不配置，默认是input搜索
        // 搜索类型：
        //      1、输入框 type='input'， 默认
        //      2、时间 type='date'
        //      3、数字 type='number'
        //      4、下拉框 type='select'
        this.searchComponentData = [
            {
                showName: '生产机号',
                name: 'machineNumber',
                type: 'select',
                optionList: []
                // url:'/base/dic/get/machine_number'
            },
            {
                showName: '单位',
                name: 'unit',
                type: 'select',
                url:'/base/dic/get/unit'
            },
            {
                showName: '库区',
                name: 'waCode',
                type: 'select',
                optionList: []
                // url: '/base/data/area/get/wa_code'
            },
            // {
            //     showName: '库位',
            //     name: 'wlCode',
            //     type: 'select',
            //     optionList: []
            //     // url: '/base/data/location/get/wl_code'
            // },
            {
                showName:'重量',
                name:'weight',
                type:'number',
                maxName:'weightMax',
                minName:'weightMin'
            },
            {
                showName: '等级',
                name: 'grade',
                type: 'select',
                optionList: [//下拉框的信息
                      {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'1',
                        optionShow:'一等品'
                    },{
                        optionKey:'2',
                        optionShow:'二等品'
                    },{
                        optionKey:'3',
                        optionShow:'处理品'
                    }
                ]
            },
            {
                showName: '级别',
                name: 'level',
                type: 'select',
                optionList: [//下拉框的信息
                      {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'A',
                        optionShow:'A'
                    },{
                        optionKey:'B',
                        optionShow:'B'
                    },{
                        optionKey:'C',
                        optionShow:'C'
                    },{
                        optionKey:'D',
                        optionShow:'D'
                    }
                ]
            },
            // {
            //     showName: '类型',
            //     name: 'type',
            //     type: 'select',
            //     optionList: [//下拉框的信息
            //           {
            //             optionKey:'',
            //             optionShow:''
            //         },{
            //             optionKey:'0',
            //             optionShow:'正品'
            //         },{
            //             optionKey:'1',
            //             optionShow:'样品'
            //         }
            //     ]
            // },
            {
                showName: '出库时间',
                name: 'gmtCreate',
                type: 'date',
                maxName: 'gmtCreateMax',
                minName: 'gmtCreateMin',
                showTime: '1'
            }
        ];

    }

    // optionList:[] 扩展
    componentWillMount() {
        // const dicType = 'model_type_p';
        const dicType = 'machine_number';
        const options= {
            url: '/base/dic/get/' + dicType,
            type: 'get',
            condition:{}
        };
        //先写死，后面再改
        fetchData(this, options, this.dicInitCallBackHandle);

        const optionsArea = {
            url: '/base/data/area/get/wa_code',
            type: 'get',
            condition:{}
        };
        fetchData(this, optionsArea, this.areaInitCallBackHandle);
    }

    //下拉框 初始化
    dicInitCallBackHandle = (resData)=>{
        //alert('resData' + JSON.stringify(resData, null, 4));
        let optionList = [];
        let tmp = {};
        tmp.optionKey = '';
        tmp.optionShow = '';
        optionList.push(tmp);
        resData.data.map( (e,index) => {
            let tmp = {};
            tmp.optionKey = Number(e.dicCode);
            tmp.optionShow = e.dicName;
            optionList.push(tmp);
        });

        this.tableColumn.data[9].showOption = optionList;
        this.searchComponentData[0].optionList = optionList;
    }
    areaInitCallBackHandle = (resData)=>{
        //alert('resData' + JSON.stringify(resData, null, 4));
        let optionList = [];
        let tmp = {};
        tmp.optionKey = '';
        tmp.optionShow = '';
        optionList.push(tmp);
        resData.data.map( (e,index) => {
            let tmp = {};
            tmp.optionKey = e.dicCode;
            tmp.optionShow = e.dicName;
            optionList.push(tmp);
        });

        this.tableColumn.data[12].showOption = optionList;
        this.searchComponentData[2].optionList = optionList;
    }

    // 行操作
    rowHandles = (strHandles, rowObj) => {
        // if(strHandles === 'edit'){
        //     this.editHandle(rowObj);
        // }else if(strHandles === 'delete'){
        //     this.deleteHandle(rowObj);
        // }else if(strHandles === 'add'){
        //     this.addHandle();
        // }
    }


    //刷新列表
    refreshHandle = () => {
        this.refs.proHandOutSnList.refreshHandle();
    }

    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return(
            <div>
                <ListBox
                    ref = 'proHandOutSnList'
                    title="手工出库明细查询"
                    isHideLeft={isHideLeft}
                    tableColumnData = {this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url = '/product/handSn/list'
                    rowHandles = {this.rowHandles}
                    rowOperation = {this.rowOperation}
                    headerOperation = {this.headerOperation}
                    isRowSingle = "true"
                />
            </div>
        )
        
    }

}